package atm;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class SavePanel   extends JPanel   implements ActionListener{
    private ATMFrame atmFrame;
    private ImageIcon sure = new ImageIcon("images/buttonSure.jpg");
    private JLabel saveMoney = new JLabel("存款金额：");
    private JTextField moneyField = new JTextField();
    private JButton sureBtn=new JButton(sure);
    private Font font = new Font("黑体",Font.BOLD,20);

    public SavePanel(ATMFrame atmFrame){
        this.atmFrame=atmFrame;
        this.setLayout(null);
        this.add(sureBtn);
        this.add(saveMoney);
        this.add(moneyField);
        saveMoney.setBounds(300,200,120,50);
        sureBtn.setBounds(400,260,140,50);
        moneyField.setBounds(400,200,140,50);
        saveMoney.setFont(font);
        sureBtn.addActionListener(this);




        this.setOpaque(false);
//        sureBtn.addActionListener(new ActionListener() {
//            @Override
//            public void actionPerformed(ActionEvent e) {
//                System.out.println("存款点击"+e.getActionCommand());
//                if( e.getSource() == sureBtn){
//                    User user=atmFrame.getLoginUser();
//                    try{
//                        user.setBlance(user.getBlance() + Double.parseDouble(moneyField.getText()));
//                    }catch (NumberFormatException e1){
//                        JOptionPane.showMessageDialog(this,"必须输入数字");
//                        return;
//                    }
//
//                    atmFrame.switchPanel("menu");
//                }
//            }
//        });
    }
    public void actionPerformed(ActionEvent e) {
        System.out.println("存款点击"+e.getActionCommand());
        if (e.getSource() == sureBtn) {
            User user = atmFrame.getLoginUser();
            try{
                user.setBlance(user.getBlance() + Double.parseDouble(moneyField.getText()));
                System.out.println(user.getBlance());
            }catch (NumberFormatException e1){
                JOptionPane.showMessageDialog(this,"必须输入数字");
                return;
            }
            atmFrame.switchPanel("menu");
        }
    }

}
